import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MovieScroll extends StatelessWidget {
  final List _list = [
    {
      "name": "攀登者",
      "img":
          "https://p0.meituan.net/170.230/movie/4c01895cfd53e82f7c3048c407974a6b4739229.jpg"
    },
    {
      "name": "诛仙",
      "img":
          "https://p0.meituan.net/170.230/movie/845dce25ba800e91ac591b683a0c3ba92450317.jpg"
    },
    {
      "name": "小小的愿望",
      "img":
          "https://p0.meituan.net/170.230/movie/d18915868f6e3e6e287162354700690f2338229.jpg"
    },
    {
      "name": "中国机长",
      "img":
          "https://p0.meituan.net/170.230/moviemachine/4de45617746dae456738bc322670cb88562422.jpg"
    },
    {
      "name": "名侦探柯南",
      "img":
          "https://p0.meituan.net/170.230/moviemachine/b7362f555340906684944957dfc8d5421530646.jpg"
    },
    {
      "name": "美食大冒险",
      "img":
          "https://p0.meituan.net/170.230/movie/f0614f9d08e84abfe947531c491b1cf55397550.jpg"
    },
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          height: 238,
          // 一个多行排列的组件，可以实现滚动效果
          child: ListView(
            scrollDirection: Axis.horizontal,
            children: <Widget>[
              _ImgItem(img: _list[0]["img"]),
              _ImgItem(img: _list[1]["img"]),
              _ImgItem(img: _list[2]["img"]),
              _ImgItem(img: _list[3]["img"]),
              _ImgItem(img: _list[4]["img"]),
              _ImgItem(img: _list[5]["img"]),
            ],
          ),
        ),
      ),
    );
  }
}

class _ImgItem extends StatelessWidget {
  _ImgItem({Key key, @required this.img}):super(key: key);
  final String img;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 170,
      child: Image(
        image: NetworkImage(
            '$img'),
        fit: BoxFit.cover,
      ),
      decoration: BoxDecoration(color: Colors.green),
    );
  }
}
